using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ScytheEngine
{
	public class Object
	{
		#region Data Members

		protected Vector3 m_Position;
		protected Vector3 m_Scaling;
		protected Quaternion m_Rotation;

        protected string m_Shader;

		#endregion

		#region Ctors

		public Object()
		{
			m_Position = new Vector3( 0, 0, 0 );
			m_Scaling = new Vector3( 1, 1, 1 );
			m_Rotation = new Quaternion( 0, 0, 0, 1 );
		}

		#endregion

		#region Methods

		public void Draw(GraphicsDevice gfxDev)
		{
			if(this is IRenderable)
			{
                Shader objShader = ShaderManager.GetShader(m_Shader);
                if( objShader == null)
                {
                    objShader = ShaderManager.DefaultShader();
                }

                if( objShader != null)
                {
					objShader.SetParameters( this );
                    objShader.Effect.Begin();
                    foreach (EffectPass pass in objShader.Effect.CurrentTechnique.Passes)
                    {
                        pass.Begin();
                        ((IRenderable)this).Render(gfxDev);
                        pass.End();
                    }
                    objShader.Effect.End();
                }
			}
			if(this is IRenderableChildren)
			{
				( (IRenderableChildren)this ).RenderChildren( gfxDev );
			}
		}

		public void Update(GameTime gameTime)
		{
			if(this is IUpdateable)
			{
				((IUpdateable)this).Update( gameTime );
			}
		}

        public void SetShader(string shader)
        {
            m_Shader = shader;
        }

		#endregion

		#region Properties

		public Vector3 Scaling
		{
			get { return m_Scaling; }
		}

		public Vector3 Position
		{
			get { return m_Position; }
		}

		public Quaternion Rotation
		{
			get { return m_Rotation; }
		}

		#endregion
	}
}
